/**
 * Created by forcht on 2018/5/17.
 */
public class Solution {
    public String convert(String s, int nRows) {
        if (nRows == 1) return s;
        StringBuilder[] str = new StringBuilder[nRows];
        for (int j = 0; j < nRows; j++) str[j] = new StringBuilder();
        int i = 0;
        int row = 0;
        int flag = 1;
        while (i < s.length()) {
            str[row].append(s.charAt(i));
            i++;
            row += flag;
            if (row >= nRows) {
                row = nRows - 2;
                flag =-1;
            } else if (row < 0) {
                row = 1;
                flag =1;
            }

        }
        for (i = 1; i < nRows; i++) str[0].append(str[i]);
        return str[0].toString();
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.convert("ABCDEF", 4));
    }
}
